package top.lenjon.lib.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.lenjon.lib.entity.Admin;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * <p>
 * 管理员 Mapper 接口
 * </p>
 *
 * @author wei
 * @since 2020-11-09
 */
@Repository
public interface AdminMapper extends BaseMapper<Admin> {

    /**
     * md5加密000000
     *
     * @param id
     * @return int
     */
    @Update("UPDATE user_detail SET password='670b14728ad9902aecba32e22fa4f6bd' WHERE id=#{id}")
    int resetUserPswById(int id);

    @Update("UPDATE admin SET password='670b14728ad9902aecba32e22fa4f6bd' WHERE id=#{id}")
    int resetAdminPswById(int id);

    @Select("SELECT password FROM admin WHERE username =#{username} AND enabled = 1 LIMIT 0,1")
    String getPasswordByUsername(String username);

    @Select("SELECT * FROM admin WHERE enabled = 1")
    List<Admin> getAll();

    @Select("SELECT * FROM admin WHERE username = #{username} AND enabled = 1")
    Admin getAdminByName(String username);
}
